#ifndef _CallpConstants_h_
#define _CallpConstants_h_
////////////////////////////////////////////////////////////////////////////////
/// @file CallpConstants.h
/// @brief This file contains all the common tunable constants for Callp.
///
/// This file contains all the common tunable constants for Callp.
///
/// Maintained by: LTE eNB Callp Application Team
///
/// Copyright(c) 2009-2010 Nanocell, All Rights Reserved
///
/// CONFIDENTIALITY AND RESTRICTED USE
///
/// This software, including any software of third parties embodied herein,
/// contains information and concepts which are confidential to Nanocell
/// and such third parties. This software is licensed for use
/// solely in accordance with the terms and conditions of the applicable
/// license agreement with Nanocell or its authorized distributor.
////////////////////////////////////////////////////////////////////////////////

#include <stdint.h>
#include <string>
#include "CallpConstants_xml.h"

const uint8_t MAXIMUM_NUMBER_OF_SRB = 1;
const uint8_t MAXIMUM_CELLS_MEASURED = 32;

const uint32_t MAXIMUM_NUMBER_OF_CELL_PROCESSES    = 6;
const uint32_t MAXIMUM_NUMBER_OF_CELLS_PER_PROCESS = 3;
const uint32_t MAXIMUM_NUMBER_OF_CELLS             = MAXIMUM_NUMBER_OF_CELLS_PER_PROCESS*MAXIMUM_NUMBER_OF_CELL_PROCESSES;

//@todo it is useless, remove it later.
const uint32_t MAX_CALL_PER_CELL                   = 12;

//uppper limit supported by UE pool
const uint32_t MAXIMUM_NUMBER_OF_UE_PER_CELL       = 200;

const uint32_t MAXIMUM_NUMBER_OF_BEARER_PER_UE = 3;

//The following constants are for Id pools and proxies. They are engineered parameters.
//The maximum size is 30% more than the maximum configured with handoff taken into consideration.
//The low water mark is 20% of the maximum.
//The high water mark is 10% above the maximum.
const uint32_t MAXIMUM_SIZE_OF_CONTEXT_ID_PROXY = (130*MAXIMUM_NUMBER_OF_CELLS_PER_PROCESS*MAXIMUM_NUMBER_OF_UE_PER_CELL)/100;
const uint32_t LOW_WATER_MARK_OF_CONTEXT_ID_PROXY = (20*MAXIMUM_SIZE_OF_CONTEXT_ID_PROXY)/100;
const uint32_t HIGH_WATER_MARK_OF_CONTEXT_ID_PROXY = (110*MAXIMUM_SIZE_OF_CONTEXT_ID_PROXY)/100;
const uint32_t INCREMENT_OF_CONTEXT_ID_PROXY = (20*MAXIMUM_SIZE_OF_CONTEXT_ID_PROXY)/100;

const uint32_t MAXIMUM_SIZE_OF_CONTEXT_ID_POOL = MAXIMUM_SIZE_OF_CONTEXT_ID_PROXY*MAXIMUM_NUMBER_OF_CELL_PROCESSES;
const uint32_t LOW_WATER_MARK_OF_CONTEXT_ID_POOL = (20*MAXIMUM_SIZE_OF_CONTEXT_ID_POOL)/100;
const uint32_t INCREMENT_OF_CONTEXT_ID_POOL = (20*MAXIMUM_SIZE_OF_CONTEXT_ID_POOL)/100;

const uint32_t MAXIMUM_SIZE_OF_TE_ID_PROXY = (130*MAXIMUM_NUMBER_OF_CELLS_PER_PROCESS*MAXIMUM_NUMBER_OF_UE_PER_CELL*MAXIMUM_NUMBER_OF_BEARER_PER_UE)/100;
const uint32_t LOW_WATER_MARK_OF_TE_ID_PROXY = (20*MAXIMUM_SIZE_OF_TE_ID_PROXY)/100;
const uint32_t HIGH_WATER_MARK_OF_TE_ID_PROXY = (110*MAXIMUM_SIZE_OF_TE_ID_PROXY)/100;
const uint32_t INCREMENT_OF_TE_ID_PROXY = (20*MAXIMUM_SIZE_OF_TE_ID_PROXY)/100;

const uint32_t MAXIMUM_SIZE_OF_TE_ID_POOL = MAXIMUM_SIZE_OF_TE_ID_PROXY*MAXIMUM_NUMBER_OF_CELL_PROCESSES;
const uint32_t LOW_WATER_MARK_OF_TE_ID_POOL = (20*MAXIMUM_SIZE_OF_TE_ID_POOL)/100;
const uint32_t INCREMENT_OF_TE_ID_POOL = (20*MAXIMUM_SIZE_OF_TE_ID_POOL)/100;

const uint32_t MAXIMUM_REQUEST_RETRY_FOR_IDS = 3;

// NOTE: This value must be equal to MasterSystemInformationBlock::SFN_BIT_OFFSET defined
// in: /cc/bts/ltemac/callp/module/rlc/src/CellCallpL2Interface.h
const uint16_t MIB_SFN_OFFSET_IN_BITS = 6;

// SIB8's IE systemTimeInfo's bit offset invalid value.
// when invalid, L2'll not fill that IE.
const uint32_t INVALID_SIB8_SYS_TIME_OFFSET = 0xFFFFFFFF;

///@todo perhaps these can be folded into a single constant
const uint8_t MAX_GTPU_ROUTING_RECORDS_PER_REQUEST = 10;
const uint8_t MAX_PDCP_INFO_PER_REQUEST = 10;

/// @todo find common location for OptionString for fifo base name
const std::string CELL_CALLP_ENB_FIFO_NAME_BASE = "/tmp/CellEnbIf_";

const std::string CELL_CALLP_CALLP_FIFO_NAME_BASE = "/tmp/CellCellIf_";

const uint32_t MAX_NUMBER_OF_USER_INSTANCES = 10;

/// RBID and LCID constants
//
//Note: MAX_RB_NUMBER is used by BearerDlog struct which is modeled to XML schema.
//      However, the constant declaration can't be modeled, so we define a macro instead.
//      So, if changed in future, it should be manually synced with below definition to below file:
//
//          /cc/ltebts/app/oam/module/lte_lm/dlog_model/datatype/datatype_CallpDlogDefinitions.xml
//
const RbIdType MAX_RB_NUMBER = 11; //number of RB per UE, limited by LCID number
const RbIdType MAX_SRB_NUMBER = 3; //max number of SRB
const RbIdType MAX_DRB_NUMBER = 8; //number of DRB per UE, limited by LCID number
const RbIdType MAX_TRB_ID = 8; //Max RB ID for DRB
const RbIdType MIN_TRB_ID = 1;
const RbIdType MAX_SRB_ID = 2; //Max RB ID for SRB
const RbIdType MIN_SRB_ID = 1;
const uint16_t MIN_SRB_LCID = 1; //SRB1
const uint16_t MAX_SRB_LCID = 2; //SRB2
const uint16_t MIN_DRB_LCID = 3; //Min LCID for DRB
const uint16_t MAX_DRB_LCID = 10; //Max LCID for DRB

// It is the standard-offset currently set for ul-earfcn. According to T36.104
// when seeing standard-offset, ul-earfcn should be derived from dl-earfcn by
// ul-earfcn = dl-earfcn + (n-offset-dl - n-offset-ul)
const int16_t STANDARD_OFFSET = -24;

// These inline functions can be used to convert between Rbid and LcId.
//  Usage: uint16_t drbLcId =  DRB_RBID_2_LCID(drbRbId);

inline RbIdType DRB_LCID_2_RBID(uint16_t lcId)
{
    return ((lcId - MIN_DRB_LCID) + MIN_TRB_ID);
}

inline uint16_t DRB_RBID_2_LCID(RbIdType rbId)
{
    return ((rbId - MIN_TRB_ID) + MIN_DRB_LCID);
}

// For SRBs conversion, currently RbId and LcId are the same,
//  but the following two are defined so that we can change one place (here)
//  to update the conversion should future spec changed in term of the
//  RbId or LcId range for SRBs.
inline uint16_t SRB_RBID_2_LCID(RbIdType rbId)
{
    return rbId;
}
inline RbIdType SRB_LCID_2_RBID(uint16_t lcId)
{
    return lcId;
}


/// L2 Ue Capability Container constants
const uint16_t MIN_UE_CATEGORY = 1;
const uint16_t MAX_UE_CATEGORY = 16;

// Number of Tx Path per cell.
const uint8_t MAX_NUM_OF_TX_PATH_PER_CELL = 3;

const uint32_t INVALID_GLB_CELL_ID = 0xFFFFFFFF;

// callp TLV message protocal number
enum TlvProtocolNumber
{
    TLV_MESSAGE_TC_PROTOCOL_NUMBER,
    CALLP_TO_GTPU_CONTROLMSG_PROTOCOL_NUMBER,
    CELL_L2CALLP_INTERFACE_CONFIG_PROTOCOL_NUMBER,
    CCP_PROTOCOL_NUMBER,
    CELLCALLP_ENDPOINT_FAC_PROTOCOL_NUMBER,
    CELLCALLP_ENDPOINT_PROTOCOL_NUMBER,
    CONTEXTID_POOL_PROXY_PROTOCOL_NUMBER,
    ENBCTRL_TO_BHCTRL_INTERFACE_MSG_PROTOCOL_NUMBER,
    ENB_TO_L2IF_CELL_DETECTION_PROTOCOL_NUMBER,
    ENB_TO_L2IF_PAGING_PROTOCOL_NUMBER,
    ENB_TO_L2INTERFACE_BROADCASTMSG_PROTOCOL_NUMBER,
    ENDPOINT_FACTORY_PROTOCOL_NUMBER,
    ENDPOINT_PROTOCOL_NUMBER,
    GTPU_MESSAGE_PROTOCOL_NUMBER,
    INTRA_ENB_HO_MESSAGE_PROTOCOL_NUMBER,
    L2_COMMON_MESSAGE_PROTOCOL_NUMBER,
    MIB_SIB_UPD_MESSAGE_PROTOCOL_NUMBER,
    OAM_MESSAGE_PROTOCOL_NUMBER,
    RB_CONFIGURATION_PROTOCOL_NUMBER,
    S1_ENDPOINT_FACTORY_PROTOCOL_NUMBER,
    S1_ENDPOINT_PROTOCOL_NUMBER,
    TEID_POOL_PROXY_PROTOCOL_NUMBER,
    ENB_CTRL_AND_CALLP_CTRL_MSG_PROTOCOL_NUMBER,
    SON_PCI_PROTOCOL_NUMBER,
    CELL_STATE_PROTOCOL_NUMBER,
    CELL_TRACE_PROTOCOL_NUMBER
};

const uint16_t CALLP_MAX_NBR_CELL_NUM = 32;

const uint16_t ANR_ADDITIONAL_REPORT_TIME = 15;

const std::string CELL_CALLP_ANR_UNIX_SOCKET_NAME = "/tmp/CellAnrSock_";

const uint16_t ANR_SOCK_BUF_LEN = 1024;

// X2 Constants
const uint16_t X2_SCTP_DEFAULT_PORT = 36422;

#endif
